package com.sangmo.fts.process.factoring.repo;

import com.sangmo.boot.framework.plugin.dataview.spi.jpa.IJpaDataViewRepo;
import com.sangmo.fts.process.factoring.model.FfFactoringContract;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface FfFactoringContractRepo extends IJpaDataViewRepo<FfFactoringContract> {

    @Query("SELECT a FROM FfFactoringContract a where a.id = :contractId AND a.trainingId = :trainingId AND NOT EXISTS(SELECT 1 from  FfTransferApply ta WHERE ta.contractId = a.id AND ta.deleted = 0)")
    FfFactoringContract findAvailableById(@Param("contractId")Long contractId, @Param("trainingId") Long trainingId);
}
